// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import Vant from 'vant'
import 'vant/lib/index.css'
import App from './App'
import router from './router'
import vueTap from 'v-tap'
import store from './store';
import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'
import 'lib-flexible/flexible'
import { Lazyload } from 'vant';
import md5 from 'md5';
import { PullRefresh } from 'vant';
import axios from 'axios';

Vue.prototype.$md5 = md5;

Vue.use(PullRefresh);
Vue.use(Lazyload);
Vue.use(VueAwesomeSwiper)
Vue.use(vueTap)
Vue.use(Vant);
Vue.config.productionTip = false

// http request拦截器
axios.interceptors.request.use((config)=>{
	if(store.state.token){
		config.headers.authorization = 'Bearer '+store.state.token;
	}
	return config;
},(err)=>{
	return Promise.reject(err);
})

// http response拦截器
axios.interceptors.response.use((response)=>{
	return response;
},(err)=>{
	if(err.response.status === 401){
		routeer.replace({
			path: 'login'
		})
	}
	return Promise.reject(err.response.data)
})


/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
